<%@ page isELIgnored="false" %>
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% 
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html lang="ch">
    <head>
    	<base href="<%=basePath %>">
		<title>MINISHOP-“快”到家，才“购”味</title>
        <link href="views/front/bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<link href="views/front/css/font-awesome.min.css" rel="stylesheet">
		<link href="views/front/css/style.css" rel="stylesheet">
		<link href="views/front/css/responsive.css" rel="stylesheet">
		<link href="views/front/css/custom.css" rel="stylesheet">
		<style type="text/css">
			.default{
				border:2px solid red;
			}
		</style>
    </head>
	<body>
        
        <!-- 注册弹窗-->
        <iframe id="registerDIV" class="pushDiv" scrolling="no" src="views/front/register.jsp"></iframe>
        
         <!-- 登录弹窗-->
        <iframe id="loginDIV" class="pushDiv" scrolling="no" src="views/front/login.jsp"></iframe>
        
        <!-- 增加地址弹窗-->
        <iframe id="addAddress" name="addAddress" class="pushDiv" scrolling="no" src="views/front/addAddress.jsp"></iframe>
        
        <!-- 订单详情弹窗-->
        <iframe id="orderDetailsDIV" name="orderDetailsDIV" class="pushDiv" scrolling="no" src="views/front/orderDetails.jsp"></iframe>
        
        <iframe id="commonsIt" class="pushDiv" scrolling="no" src="views/front/commonsIt.jsp"></iframe>
        
        
		<!-- header -->
		<header class="header">
			<!-- header top -->
			<div class="header-top">
				<div class="container">
					<div class="row">
						<div class="col-sm-3">
							<ul class="list-inline">
								<li>
									<div class="dropdown">
										<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img  src="views/front/images/chinese.jpg" alt="" /> 中国 <i class="fa fa-angle-down"></i></a>
										<ul class="dropdown-menu">
											<li><a href="javascript:void(0)">中国</a></li>
										</ul>
									</div>
								</li>
								<li>
									<div class="dropdown">
									</div>
								</li>
							</ul>
						</div>
						<div class="col-sm-4">
						</div>
						<c:choose>
							<c:when test="${userInfo eq null}">
								<div class="col-sm-5" id="user_head">
                                    <ul class="list-inline pull-right">Hi,尊敬的用户，您可以
                                        <li><a href="javascript:open_div('loginDIV')" ><i class="fa fa-user"></i> 登录</a></li>
                                        <li><a href="javascript:toShopCar()" ><i class="fa fa-heart-o"></i> 购物车 (${shopCarCount })</a></li>
                                        <li><a class="register" href="javascript:open_div('registerDIV')" >注册</a></li>
                                    </ul>	
                                </div>
							</c:when>
							<c:otherwise>
								<div class="col-sm-5" id="user_head">
                                    <ul class="list-inline pull-right">Hi,
                                        <li><a href="javascript:toUserInfo()" ><i class="fa fa-user"></i> ${userInfo.uname }</a></li>
                                        <li><a href="javascript:toShopCar()" ><i class="fa fa-heart-o"></i> 购物车 (${shopCarCount })</a></li>
                                        <li><a class="exit" href="javascript:exit()" >登出</a></li>
                                    </ul>	
                                </div>
							</c:otherwise>
						</c:choose>	
				</div>
			</div>
			
			<!-- logo and adds -->
			<div class="logo-add">
				<div class="container">
					<div class="row">
						<div class="col-sm-4">
							<div class="logo"><i class="fa fa-diamond"></i>MINISHOP觅你</div>
						</div>
						<div class="col-sm-8">
							<h3 class="add bb-year-end-ribbon hidden-xs"><img src="views/front/images/red-tablet.png" width="40px;" alt="" /> 
							<span>Hi!你想要的 <span>商品</span> 都在这里</span> <button class="btn btn-default" onClick="javascript:open_div('registerDIV')"> 新用户注册 </button></h3>
						</div>
					</div>
				</div>
			</div>
			
			<!-- header bottom -->
			<div class="header-bottom">
				<div class="row">
					<div class="col-sm-12">
						<nav class="navbar navbar-default">
							<div class="container">
								<!-- Brand and toggle get grouped for better mobile display -->
								<div class="navbar-header">
									<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#header-bottom" aria-expanded="false">
										<span class="sr-only">Toggle navigation</span>
										<span class="icon-bar"></span>
										<span class="icon-bar"></span>
										<span class="icon-bar"></span>
									</button>
								</div>

								<!-- Collect the nav links, forms, and other content for toggling -->
								<div class="collapse navbar-collapse" id="header-bottom">
									<ul class="nav navbar-nav">
										<li class="active"><a href="javascript:void(0)" onClick="javascript:location.href='index.jsp'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">首页</a></span>
										<li><a href="javascript:void(0)" onClick="javascript:location.href='views/front/product.jsp'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">购物</a><span class="label label-danger text-center hidden-xs">New <i class="fa fa-caret-right"></i></span></li>
										<li><a href="javascript:void(0)" onClick="javascript:location.href='views/front/about-us.jsp'">关于MINISHOP</a> </li>
										<li><a href="javascript:void(0)" onClick="javascript:location.href='views/front/contact-us.jsp'">联系我们</a></li>
									</ul>
								</div>
							</div>
						</nav>
					</div>	
				</div>	
			</div>	
		</header>	
		
		<!-- 中间的部分 -->
		<div class="center" style="padding:100px auto;background:rgba(0,0,0,.1);">
			<!-- 中间内容白块 -->
			<div class="white_block" style="margin:20px 0px;width:80%;background:rgba(255,255,255);padding:20px 0px;margin:auto auto">
				<div id="address_block" style="padding:10px;width:90%;border:1px solid black;margin:0px auto;">
					<h2>管理收货地址</h2>
					<c:forEach items="${addressList }" var="item" varStatus="status">
						<div id="${item.addrid }" class="address_item" onClick="javascript:clickAddress(this,${item.addrid })" style="margin:5px 0px;background:black;color:rgb(255,255,255);width:200px;height:100px;">
							<span class="reciver_text">${item.receiver }</span></br>
							<span>手机号：<span class="tel_text">${ item.tel}</span></span></br>
							<span>地址：</span><span class="address_text">${item.address }</span></br>
							<input type="button" style="color:black" class="deleteButton" value="删除"  onClick="deleteAddress(${item.addrid })" />
						</div>
						<c:if test="${status.last }">
							</br></br>
						</c:if>
					</c:forEach>
					<a href="javascript:openAddress('${userInfo.userid }')" style="">添加收货地址</a>
				</div>
			</div><!-- 收货地址部分完成 -->
			
			<!-- 订单确认 -->
			<div id="order_details_block" style="padding:10px;width:80%;background:white;margin:0px auto;">
				<div style="border:1px solid black;padding:10px;width:92%;background:white;margin:0px auto;" id="order_details">
					<h2 style="color:red">历史订单详情</h2>
					<table id="order_detaile_table" style="color:black">
						<tr>
							<th>订单号</th>
							<th>宝贝</th>
							<th>购置数量</th>
							<th>价格</th>
							<th>状态</th>
							<th>时间</th>
							<th>评价</th>
						</tr>
						<c:forEach items="${orderDetails }" var="item">
							<tr class="commodity_item" style="">
								<td style="display:none" class="commodityid">${item.orderid }</td>
								<td>${item.orderid }</td>
								<td></td>
								<td>${item.totalnum }</td>
								<td>￥<span class="price">${item.totalprice }</span></td>
								<td class="orderStatus">
									<c:if test="${item.status eq 0 }">
										未付款
									</c:if>
									<c:if test="${item.status eq 1 }">
										未发货
									</c:if>
									<c:if test="${item.status eq 2 }">
										已发货
									</c:if>
									<c:if test="${item.status eq 3 }">
										已收取
									</c:if>
									<c:if test="${item.status eq 4 }">
										完成
									</c:if>
								</td>
								<td>${item.createdate}</td>
							</tr>
							<c:forEach items="${item.orDetailsList }" var="item1">
								<tr>
								<tr>
									<td></td>
									<td>${item1.commodityObj.cname }</td>
									<td>${item1.detanum }</td>
									<td>￥${item1.detanum* item1.commodityObj.price }</td>
									<td></td>
									<td></td>
									<td><a href="javascript:commonsIt(${item.orderid },${item1.commodityObj.commid })">评价</a></td>
								</tr>
							</tr>
							</c:forEach>
							<tr style="width:100px;height:30px;"><td></td></tr>
						</c:forEach>
					</table>
				</div>
			</div><!-- 订单确认 完成-->
		</div>
		
		<footer>
			<div class="footer-bottom">
				<div class="container">		
					<div class="row">	
						<div class="col-sm-12 text-center">
							<p>Copyright 2015 made by <a href="javascript:void(0)">周丹</a> 设计实现</p>
						</div>
					</div>
				</div>	
			</div>
		</footer>
			
        <!-- ALL JAVASCRIPT -->         
        <script src="views/front/js/jquery.js"></script>
        <script src="views/front/bootstrap/js/bootstrap.min.js"></script>
        <script src="views/front/js/custom.js"></script>
        <script type="text/javascript">
        	var addrid='';
        	
        	function clickAddress(obj,id){
        		addrid=id;
        		$(".address_item").attr("class","address_item");
        		$(obj).attr("class","address_item default");
        		$("#address_text").html($(obj).find(".address_text").html());
        		$("#conectP").html($(obj).find(".reciver_text").html()+"&nbsp;&nbsp;"
        			+$(obj).find(".tel_text").html());
        	}
        	
        	function openAddress(userid){
        		open_div('addAddress');
        		$("#addAddress").contents().find("#userid").val(userid);
        	}
        	
        	function deleteAddress(addrid){
        		alert(addrid);
        		$.ajax({
        			url:'front/address/'+addrid,
        			type:'DELETE',
        			dataType:'JSON',
        			success:function(data){
        				if(data.code=='0000'){
        					$("#"+addrid).remove();
        				}else{
        					alert(data.msg);
        				}
        			}
        		});
        	}
        	
        	function openOrderDetails(obj){
        		alert(obj);
        	}
        	
        	function commonsIt(orderid,commid){
        		open_div("commonsIt");
        		$("#commonsIt").contents().find("#orderid").val(orderid);
        		$("#commonsIt").contents().find("#commid").val(commid);
        	}
        
	        $(function(){
        		$(".total").html(parseFloat($(".total").html()*$(".num").val()).toFixed(2));

	        	var totalprice=0;
        		$(".total").each(function(){
        			totalprice+=parseFloat($(this).html());
        		});
        		$("#totalprice").html(totalprice.toFixed(2));
        		
	        	
	        });
        </script>
    </body>
</html>